#include "VertexFormats.fx"
#include "Fog.fx"

float4x4 world_view_proj : WORLD_VIEW_PROJECTION;
float4x4 world : WORLD;
float3 camera_pos : CAMERA_POS;

float3 light_color;
float3 fog_color = float3(0, 0, 0);
float fog_start = 13.0f;
float fog_length = 10.0f;
float opacity = 0.2;

struct VSOut 
{
    float4 pos : POSITION;
	float3 world_pos : TEXCOORD0;
    float3 color : COLOR;
};

VSOut VS_Light(VertexPosNormal input)
{
    VSOut output;
	output.pos = mul(float4(input.pos, 1), world_view_proj);
	output.world_pos = mul(float4(input.pos, 1), world);
	output.color = light_color;
    return output;
}

float4 PS_Light(VSOut input) : COLOR
{
	float3 color = quadraticFog(input.world_pos, camera_pos, light_color,
		fog_color, fog_start, fog_start + fog_length);
    return float4(color, opacity);
}

technique t0
{
    pass p0
    {
        VertexShader = compile vs_2_0 VS_Light();
        PixelShader = compile ps_2_0 PS_Light();
		
		AlphaBlendEnable = true;
		SrcBlend = srcAlpha;
		DestBlend = one;
		ZEnable = false;
    }
}
